<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <#include "../common/header.ftl">

    <script type="text/javascript">
    	$(function(){

    		$('#pagination').twbsPagination({
    			totalPages:${result.pages} || 1,
    			startPage:${result.pageNum},
    			visiblePages:${result.pageSize},
    			first:"首页",
    			prev:"上页",
    			next:"下页",
    			last:"尾页",
    			//event 表示事件对象
    			//page 表示页码: 当前页
    			onPageClick:function(event, page){
    				//讲当前页设置page值
    				$("#currentPage").val(page);
    				//表单提交gjk,mb/.
    				$("#searchForm").submit();
    			}
    		});

            //修改按钮
            $(".editBtn").click(function(){
                $("#editForm")[0].reset();
                var json = $(this).data("json");
                $("#strategyCatalogId").val(json.id);
                $("#name").val(json.name);
                $("#sequence").val(json.sequence);
                $("#state").val(json.state+"");//转成字符串再回显

                //回显表单中的的攻略下拉框
                $("#strategyForm option[value="+json.strategyId+"]").prop('selected',true);
                //让插件执行更新操作
                $("#strategyForm").trigger("chosen:updated");

                $("#strategyCatalogModal").modal('show');
            })


            //保存按钮
            $("#saveBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    showMessager(data);
                });
            })
            //新增按钮
            $(".addBtn").click(function () {
                $("#editForm")[0].reset();
                //把查询下拉框的攻略id设置到表单额攻略下拉框
                //回显表单中的的攻略下拉框
                $("#strategyForm option[value="+'${(qo.strategyId)!}'+"]").prop('selected',true);
                //让插件执行更新操作
                $("#strategyForm").trigger("chosen:updated");


                $("#strategyCatalogModal").modal('show');

            })


            //获取所有攻略
            $.get('/strategy/listAll.do',function (data) {

                var html = "<option></option>";

                $.each(data,function (index, ele) {

                    html+= "<option value='"+ele.id+"'>"+ele.title+"</option>";
                })

                //两个下拉框都使用相同的数据显示

                $(".strategySelect").html(html);
                //回显查询框的攻略条件

                $("#strategyQuery option[value="+'${(qo.strategyId)!}'+"]").prop('selected',true);

                //初始化组件(同时初始化两个下拉框)调用样式要用.开头
                $(".strategySelect").chosen({
                    width:'150px ! important',
                    placeholder_text_single: "请选择攻略",
                    disable_search_threshold: 5,//大于10条就显示搜索框
                    no_results_text: "无相关攻略!"//搜索时找不到的提示
                });
            })


        })
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
        <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">

                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    攻略查询<select class="form-control strategySelect" id="strategyQuery" name="strategyId">
                    </select>
                </div>

                <button id="btn_query" class="btn btn-default">查询</button>
                <button type="button"  class="btn btn-success addBtn">新增</button>
            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>分类名称</th>
                        <th>所属攻略</th>
                        <th>排序</th>
                        <th>状态</th>
                    </tr>
                </thead>
                   <#list result.list as entity>
                       <tr>
                           <td>${entity_index+1}</td>
                           <td>${entity.name}</td>
                           <td>${entity.strategy.title}</td>
                           <td>${(entity.sequence)!}</td>
                           <td>
                               ${(entity.state)?string("启用","禁用")}
                           </td>
                           <td><a href="javascript:void(0);" class="editBtn" data-json='${entity.jsonString}'>修改</a></td>
                       </tr>
                   </#list>
            </table>
            <div style="text-align: center;">
                <ul id="pagination" class="pagination"></ul>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="strategyCatalogModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增/修改</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" id="editForm" >
                    <input type="hidden"  id="strategyCatalogId" name="id">
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name"  >
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <select class="form-control strategySelect" id="strategyForm" name="strategy.id"  >
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label for="title" class="col-sm-4 control-label">排序：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="sequence" name="sequence"  >
                        </div>
                    </div>

                    <div class="form-group" >
                        <label for="state" class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state" id="state">
                                <option value="false">禁用</option>
                                <option value="true" selected>启用</option>

                            </select>
                        </div>
                    </div>


                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" id="saveBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->



</body>
</html>